﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="CarList.aspx.cs" Inherits="TireService.Web.View.CustomerView.CarList" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1.Export, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dxwgv" %>
<%@ Register assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView" tagprefix="dxwgv" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dxe" %>

<%@ Register src="../../UserControls/ucCreateTask.ascx" tagname="ucCreateTask" tagprefix="uc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    
    <table cellpadding="0" cellspacing="2" border="0">
        <tr>
            <td>
                <img id="imgCar" alt="" src="~/Images/Medium/car_sedan_blue.png" runat="server" style="width: 32px; height: 32px" />
            </td>
            <td valign="middle">
                <h3><asp:Label ID="lblCarListHeader" runat="server" Text="Biler"></asp:Label></h3>
            </td>
        </tr>
    </table>
    <hr />

    <!-- Start: Modal popup windows -->
    <dx:ASPxPopupControl ID="pcChangeStatus" runat="server" CloseAction="CloseButton" Modal="True"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" ClientInstanceName="pcChangeStatus"
        HeaderText="Skift status" AllowDragging="False" EnableAnimation="False" EnableViewState="False">
        <ContentCollection>
            <dx:PopupControlContentControl runat="server">
                <dx:ASPxPanel ID="Panel1" runat="server" DefaultButton="btOK">
                    <PanelCollection>
                        <dx:PanelContent runat="server">
                            <table width="350px">
                                <tr>
                                    <td>Ny status</td>
                                    <td>
                                        <dxe:ASPxComboBox ID="ddlCarStatus" ClientInstanceName="ddlCarStatus" runat="server">
                                        </dxe:ASPxComboBox>
                                        <%--<asp:DropDownList ID="ddlCarStatus" runat="server"></asp:DropDownList>    --%>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <dxe:ASPxButton ID="btnSaveCarStatus" runat="server" ClientIDMode="AutoID" AutoPostBack="False" UseSubmitBehavior="False" Text="Gem">
                                            <ClientSideEvents Click="function(s, e) { ChangeCarStatus(); }" />
                                        </dxe:ASPxButton>
                                    </td>
                                </tr>
                            </table>
                        </dx:PanelContent>
                    </PanelCollection>
                </dx:ASPxPanel>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>

    <!-- Javascript -->
    <script language="javascript" type="text/javascript">
                
        // Function that handles actions selected in dropdown list
        function ActionClicked() {

            // Get selected action from dropdownlist
            var id = ddlAction.GetValue();

            if (id != null && id != 0) {

                // Change status on selected cars
                if (id == 1) {
                    // Show popup for status change
                    pcChangeStatus.Show();
                }
            }
            else 
            {
                alert('Ingen handling valgt');
            }
        }

        // Function that get all selected rows in gridview and trigger function SaveCarStatusChange
        function ChangeCarStatus() {
            
            // Get selected items in gridview and trigger event SetSelectedAsApproved
            gvCar.GetSelectedFieldValues('CarId', SaveCarStatusChange);
        }

        // Function that initiates callback to server for changing car status on selected values in gridview
        function SaveCarStatusChange(SelectedValues) {
            if (SelectedValues.length == 0) return;

            // Add selected status value in end of array
            SelectedValues.push(ddlCarStatus.GetValue());

            // Perform callback to server
            cbSaveCarStatus.PerformCallback(SelectedValues);
        }

        // Function that runs after callback is completed - hide popup and refresh gridview
        function OnCallbackSaveCarStatusComplete() {
            pcChangeStatus.Hide();

            gvCar.PerformCallback();

            alert('Status på biler ændret.');
        }

        // -- Implementation script for Create Task UserControl --
        // Functions for create task modalpopup
        function ShowCreateTaskModalPopup(element, key, key2) {
            callbackCreateTaskPanel.SetContentHtml("");
            pcCreateTask.ShowAtElement(element);
            callbackCreateTaskPanel.PerformCallback('NoAction' + '|' + key + '|' + key2);
            //ddlCar.PerformCallback(key.toString());
            CreateTaskCustomerIdKeyValue = key;
        }

    </script>

    <dx:ASPxCallback ID="cbSaveCarStatus" ClientInstanceName="cbSaveCarStatus" runat="server" OnCallback="cbSaveCarStatus_Callback">
        <ClientSideEvents CallbackError="" CallbackComplete="OnCallbackSaveCarStatusComplete" />
    </dx:ASPxCallback>

    <table border="0" cellspacing="0" cellpadding="5" width="100%">
        <tr>
            <td style="width:150px">
                <dxe:ASPxComboBox ID="ddlAction" ClientInstanceName="ddlAction" runat="server" Width="150px">
                    <Items>
                        <dxe:ListEditItem Selected="true" Value="0" Text="-- Handling --" />
                        <dxe:ListEditItem Value="1" Text="Skift status" />
                    </Items>
                </dxe:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dxe:ASPxButton ID="btnSubmitAction" runat="server" Text="Udfør" AutoPostBack="False" UseSubmitBehavior="False" Width="75px">
                    <ClientSideEvents Click="function(s, e) { ActionClicked(); }" />
                </dxe:ASPxButton>
            </td>
            <td style="width:150px">
                <dxe:ASPxComboBox ID="ddlExport" ClientInstanceName="ddlExport" runat="server" Width="150px">
                    <Items>
                        <dxe:ListEditItem Selected="True" Value="0" Text="Export pdf" />
                        <dxe:ListEditItem Value="1" Text="Export xls" />
                        <dxe:ListEditItem Value="2" Text="Export csv" />
                        <dxe:ListEditItem Value="3" Text="Export rtf" />
                    </Items>
                </dxe:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dxe:ASPxButton ID="btnExport" runat="server" Text="Exporter" OnClick="btnExport_Click" Width="75px" >
                </dxe:ASPxButton>
            </td>
            <td align="right">
                <asp:Label ID="lblView" runat="server" Text="Visning"></asp:Label>
                <asp:DropDownList ID="ddlView" runat="server" AutoPostBack="True" 
                    onselectedindexchanged="ddlView_SelectedIndexChanged">
                    <asp:ListItem Value="0">Grupper efter Status</asp:ListItem>
                </asp:DropDownList>
                &nbsp;
                <asp:Label ID="lblPageSize" runat="server" Text="Antal linjer pr side"></asp:Label>
                <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true">
                    <asp:ListItem Value="10">10</asp:ListItem>
                    <asp:ListItem Value="25">25</asp:ListItem>
                    <asp:ListItem Value="50">50</asp:ListItem>
                    <asp:ListItem Value="100">100</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
    </table>          
    <hr />            
    
    <dxwgv:ASPxGridView ID="gvCar" runat="server" ClientInstanceName="gvCar" Width="100%"
        KeyFieldName="CarId" AutoGenerateColumns="False" EnableCallBacks="True" 
        oncustomunboundcolumndata="gvCar_CustomUnboundColumnData">
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Settings ShowHeaderFilterButton="true" ShowGroupPanel="true" ShowFilterRow="True" />
        <SettingsPager AlwaysShowPager="True" PageSize="20" Position="TopAndBottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} biler)" 
                Text="Side {0} af {1} ({2} biler)" />
        </SettingsPager>
        <SettingsText ConfirmDelete="Vil du slette denne bil?" />
        <SettingsBehavior ConfirmDelete="True" AllowGroup="true" AllowDragDrop="true" />
        <Columns>
            <dxwgv:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
                    <HeaderTemplate>
                        <input type="checkbox" onclick="gvCar.SelectAllRowsOnPage(this.checked);" style="vertical-align:middle;" title="Vælg/Fravælg alle linjer på siden"></input>
                    </HeaderTemplate>
                    <HeaderStyle Paddings-PaddingTop="1" Paddings-PaddingBottom="1" 
                        HorizontalAlign="Center">
                    <Paddings PaddingTop="1px" PaddingBottom="1px"></Paddings>
                    </HeaderStyle>
            </dxwgv:GridViewCommandColumn>
            <dxwgv:GridViewDataColumn Caption="Handling" Width="92px" VisibleIndex="1">
                <DataItemTemplate>
                    <a href="javascript:void(0);" onclick="ShowCreateTaskModalPopup(this, '<%# Eval("CustomerId") %>', '<%# Container.KeyValue %>')"><img src="~/Images/Tiny/contract.png" id="img1" runat="server" alt="Opret opgave" /></a>
                </DataItemTemplate>
            </dxwgv:GridViewDataColumn>
            <%--<dxwgv:GridViewDataHyperLinkColumn FieldName="CustomerId" VisibleIndex="5" Caption="Reg.nr.">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/View/CustomerView/EditCustomer.aspx?CustomerId={0}#car" TextField="RegistrationNumber">
                </PropertiesHyperLinkEdit>
            </dxwgv:GridViewDataHyperLinkColumn>--%>
            <dxwgv:GridViewDataColumn FieldName="RegistrationNumber" VisibleIndex="4" Caption="Reg.nr.">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataHyperLinkColumn FieldName="CustomerId" VisibleIndex="5" Caption="Kundenr.">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/View/CustomerView/EditCustomerData.aspx?CustomerId={0}#car" TextField="CustomerId">
                </PropertiesHyperLinkEdit>
            </dxwgv:GridViewDataHyperLinkColumn>
            <dxwgv:GridViewDataTextColumn FieldName="BrandDescription" VisibleIndex="7" UnboundType="String" Caption="Bilmærke">
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataColumn FieldName="CarBrandId" VisibleIndex="7" Visible="false" Caption="CarBrandId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="Model" VisibleIndex="7" Caption="Model">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="Year" VisibleIndex="8" Caption="Årgang">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="CarStatusDescription" VisibleIndex="9" UnboundType="String" Caption="Status">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="CarStatusId" VisibleIndex="10" Visible="false" Caption="CarStatusId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="Createdate" VisibleIndex="12" Caption="Oprettelsesdato">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="LastTireSetChangeDate" VisibleIndex="13" Caption="Sidst dækskift">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="NextTireSetChangePlanningDate" VisibleIndex="14" Caption="Næste planlægningsdato">
            </dxwgv:GridViewDataColumn>
        </Columns>                                            
    </dxwgv:ASPxGridView>
                                        
    <dxwgv:ASPxGridViewExporter ID="gvExport" runat="server" GridViewID="gvCar">
    </dxwgv:ASPxGridViewExporter>

    <uc1:ucCreateTask ID="ucCreateTask" runat="server" />

</asp:Content>